home *** CD-ROM | disk | FTP | other *** search
- ;============== RIClock v2 ==========================
- ;= An example on how to use our commodities library =
- ;======= -------- Written by S Matty -------- =======
- ; Publicscreen search routine by S McNamara
-
-
- WBStartup
- waitstatus.w=0
- popupstatus.w=0
- timeformat.w=0
- dtformat.w=0
- cscreen.b=-1
- DEFTYPE .l
- NEWTYPE .myscreen
- pad.w
- sname$
- End NEWTYPE
- Dim List screenlist.myscreen(50)
-
- cscreen$="Workbench"
- pubopen=0
- n.l=0
- suc.l=0
- pubnum.w=0
- quitflag.l=0
- prefsopen.l=0
- twelvehour.l=0
- Statement GetPubScreenList {}
- SHARED screenlist()
-
- ClearList screenlist()
-
- ad.l=LockPubScreenList_
- UnlockPubScreenList_
-
- ad=Peek.l(ad)
-
- maxnum.w=50
- Repeat
- If Peek.l(ad+10)<>0
- sname$=Peek$(Peek.l(ad+10))
- If LockPubScreen_(sname$)
- AddItem screenlist()
- screenlist()\sname=sname$
- UnlockPubScreen_ sname$,0
- EndIf
- ad=Peek.l(ad)
- maxnum-1
- Else
- Statement Return
- EndIf
- Until maxnum=0
- End Statement
-
-
- MaxLen pubscreen$=100
- DateFormat 0
- NoCli
- WbToScreen 0
- Use Screen 0
- ShowScreen 0
- Dim tformat$(2)
- Dim dformat$(4)
- For n=1 To 2
- Read tformat$(n)
- Next n
- For n=1 To 4
- Read dformat$(n)
- Next n
- Data$ "HH:MM.SS","HH:MM"
- Data$" DD/MM/YY","MM/DD/YY","DD/MM","MM/DD"
- AddIDCMP $2000000
- screenhandle.l=Peek.l(Addr Screen(0))
- suc=GetIconObject("PROGDIR:RIClock")
-
- suc=MakeCommodity("RIClock","RIClock v0.9","A Clock On Any PublicScreen")
- If suc=0 Then End
-
- If suc
- waitstatus=FindToolType("DONOTWAIT")
- popup$=FindToolValue("CX_POPUP")
- poppub$=FindToolValue("CX_POPPUB")
- popkey$=FindToolValue("CX_POPKEY")
- xpos$=FindToolValue("XPOS")
- ypos$=FindToolValue("YPOS")
- timeformat$=FindToolValue("TIMEFORMAT")
- clockformat$=FindToolValue("CLOCKFORMAT")
- dtformat$=FindToolValue("DATEFORMAT")
- dt$=FindToolValue("DATE")
- FreeIconObject
- Gosub _usesettings
- Else
- Gosub _default
- EndIf
-
- Gosub drawtitle
- If popup$="YES"
- Gosub drawprefs
- EndIf
- ResetTimer
- t.l=0
- .main
- Repeat
- VWait
- ev.l=Event
- ew.w=EventWindow
- gh.l=GadgetHit
- ec.l=EventCode
- Select ew
- Case 0
- Gosub titleclock
- Case 1
- Gosub prefs
- Case 2
- Gosub pubscreen
- End Select
- ev=0
- ew=0
- If paused=0
- If Timer-t>=50
- t=0
- ResetTimer
- Gosub updatetitle
- EndIf
- EndIf
- If CommodityEvent
- Select ExchangeMessage
- Case CxKill
- End
- Case CxDisable
- Gosub pause
- Case CxEnable
- Gosub unpause
- Case CxAppear
- Gosub drawprefs
- Case CxDisAppear
- Gosub closeprefs
- Case CxUnique
- Gosub drawprefs
- End Select
- Select HotKeyHit
- Case 0
- Gosub drawprefs
- Case 1
- Gosub drawpub
- End Select
- EndIf
- Until quitflag
- End
-
- ; Find out all currently available public screens
- .getpubscreens:
- If pubopen=True
- GTChangeList 1,63
- EndIf
- GetPubScreenList{}
- If pubopen=True
- GTChangeList 1,63,screenlist()
- GTSetAttrs 1,63,GTTagValue(54),0
- EndIf
- Return
-
- ;Disable our commodity
- .pause:
- If paused=0 Then CloseWindow 0:SetStatus Off
- paused=-1
- Return
-
- ;Enable our Commodity
- .unpause:
- If paused=-1 Then Gosub drawtitle:SetStatus On
- paused=0
- Return
-
- ;The routine to handle all PublibScreen events
- .pubscreen:
- If ev=0 Then Return
- Select ev
- Case $200 ; Close gadget
- If pubopen
- pubopen=0
- CloseWindow 2
- EndIf
- Case $40 ; We hit something
- Select gh
- Case 63 ; The list view?
- ResetList screenlist()
- For n=0 To ec
- NextItem screenlist()
- Next n
- If screenlist()\sname<>cscreen$
- cscreen$=screenlist()\sname
- scrlock.l=LockPubScreen_(screenlist()\sname)
- If scrlock=0 Then errflag=True
- If scrlock
- CloseWindow 0
- If prefsopen=True Then Gosub closeprefs
- If pubopen=True Then Gosub closepub
- Poke.l Addr Screen(0),scrlock
- Use Screen 0
- Gosub drawtitle
- UnlockPubScreen_ 0,scrlock
- ShowScreen 0
- EndIf
- EndIf
- Case 67 ; The Update button
- Gosub getpubscreens
- End Select
- End Select
- Return
-
- ;Draw the public screen window
- .drawpub:
- Use Screen 0
- If pubopen Then Return
- Gosub getpubscreens
- Use Screen 0
- GTListView 1,63,16,14,180,80,"Screens",0,screenlist(),0
- GTButton 1,67,16,91,180,12,"Update List",0
- Window 2,(ScreenWidth/2)-130,(ScreenHeight/2)-60,260,120,$100a,"Public Screen",2,1,0
- AttachGTList 1,2
- pubopen=True
- Return
-
- .closepub: ; Close the PublicScreen window
- pubopen=0
- CloseWindow 2
- Return
-
- ;Open the clock window
- .drawtitle:
- Window 0,xpos,ypos,160,11,$f,"",2,1
- Gosub updatetitle
- Return
-
- .titleclock: ; The main clock window
- If ev=0 Then Return
- Select ev
- Case $200 ; The Close gadget
- quitflag=True
- Case $2000000 ; We have moved the window
- uw.l=Used Window
- Use Window 0
- xpos.w=WindowX
- ypos.w=WindowY
- Use Window uw
- If prefsopen=-1
- GTSetInteger 0,50,xpos
- GTSetInteger 0,51,ypos
- EndIf
- End Select
- FlushEvents
- ev=0
- Return
-
- .prefs:
- If ev=0 Then Return
- Select ev
- Case $400
- Select ec
- Case 50
- ActivateString 1,50
- Case 21
- ActivateString 1,51
- Case 25
- ActivateString 1,60
- Case 51
- ActivateString 1,61
- Case 33
- Gosub saveprefs
- Case 22
- ActivateString 1,64
- Case 16
- End
- End Select
- Case $200
- Gosub closeprefs
- Case $40
- Select gh
- Case 50
- xpos.w=GTGetInteger(0,50)
- ypos.w=GTGetInteger(0,51)
- If paused=0
- Use Window 0
- WMove xpos,ypos
- EndIf
- Case 54
- twelvehour=NOT(twelvehour)
- Case 58
- dtenabled=NOT(dtenabled)
- Case 59
- Gosub saveprefs
- Case 60
- popkey$=GTGetString(0,60)
- suc=SetHotKey(0,popkey$)
- Case 62
- popup$="YES"
- popupstatus=NOT(popupstatus)
- If popupstatus=0 Then popup$="NO"
- Case 63
- waitstatus=NOT(waitstatus)
- Case 64
- poppub$=GTGetString(0,64)
- suc=SetHotKey(1,poppub$)
- Case 65
- End
- Case 66
- Gosub _default
- Gosub closeprefs
- Gosub drawprefs
- End Select
- Case $20 ; The Mutually Exclusive gadget?
- Select gh
- Case 52
- timeformat=ec
- Case 57
- dtformat=ec
- End Select
- End Select
-
- Return
-
- .drawprefs:
- If prefsopen.l Then Return
- prefsopen.l=-1
- If paused=0
- GTInteger 0,50,20,4,48,12,"_X",0,xpos
- GTInteger 0,51,112,4,48,12,"_Y",0,ypos
-
- GTMX 0,52,4,32,14,8,"?",2|$200,"HH:MM.SS|HH:MM",timeformat
- GTMX 0,57,160,32,14,8,"?",2|$200,"DD/MM/YY|MM/DD/YY|DD/MM|MM/DD",dtformat
-
- GTText 0,55,0,24,1,1,"",0,"Time Format"
- GTText 0,56,156,24,1,1,"",0,"Date Format"
-
- GTCheckBox 0,54,4,70,16,16,"24 Hour",2
- GTCheckBox 0,58,160,70,16,16,"Enabled",2
- GTCheckBox 0,62,4,136,16,16,"PopUp?",2
- GTCheckBox 0,63,4,150,16,16,"DoNotWait",2
-
- GTButton 0,59,4,172,72,12," Save ",0
- GTButton 0,65,116,172,72,12," Quit ",0
- GTButton 0,66,226,172,80,12," Default ",0
-
- GTString 0,60,76,82,216,12," _PopKey",0,50,popkey$
- GTString 0,64,76,100,216,12," P_ubKey",0,50,poppub$
-
- GTToggle 0,54,NOT(twelvehour)
- GTToggle 0,58,dtenabled
- GTToggle 0,62,popupstatus
- GTToggle 0,63,waitstatus
-
- EndIf
- Window 1,(ScreenWidth/2)-160,(ScreenHeight/2)-100,320,200,$1000a,"Clock Prefs",2,1,0
- AttachGTList 0,1
- Activate 1
- Return
-
- ;Close the preferences window
- .closeprefs:
- If prefsopen=0 Then Return
- prefsopen.l=0
- CloseWindow 1
- Free GTList 0
- Return
-
- ;Save our preferences
- .saveprefs:
- suc=GetIconObject("PROGDIR:RIClock")
- ClearToolTypes
- If waitstatus=-1 Then NewToolType "DONOTWAIT",""
- NewToolType "CX_POPUP",popup$
- NewToolType "CX_POPPUB",poppub$
- NewToolType "CX_POPKEY",popkey$
- NewToolType "XPOS",Str$(xpos)
- NewToolType "YPOS",Str$(ypos)
- NewToolType "TIMEFORMAT",tformat$(timeformat+1)
- NewToolType "DATEFORMAT",dformat$(dtformat+1)
- NewToolType "CLOCKFORMAT",Str$(12*(twelvehour+2))
- dte$="NO"
- If dtenabled=-1 Then dte$="YES"
- NewToolType "DATE",dte$
- suc=PutIconObject("PROGDIR:RIClock")
- If suc=0 Then Request "RIClock","Error saving tooltypes"," OK ":End
- FreeIconObject
- Gosub closeprefs
- Return
-
- .updatetitle:
- hr$=Str$(Hours)
- If Len(hr$)=0 AND twelvehour Then hr$="0"+hr$
- mn$=Str$(Mins)
- If Len(mn$)=1 Then mn$="0"+mn$
- sc$=Str$(Secs)
- If Len(sc$)=1 Then sc$="0"+sc$
- dt$=Date$(SystemDate)
- day$=Str$(Days)
- month$=Str$(Months)
- year$=Str$(Years)
- If twelvehour AND Val(hr$)>12 Then hr$=Str$(Val(hr$)-12)
- Select timeformat
- Case 0
- title$=hr$+":"+mn$+"."+sc$
- Case 1
- tccounter=1-tccounter
- If tccounter=0
- title$=hr$+":"+mn$
- Else
- title$=hr$+" "+mn$
- EndIf
- End Select
- If dtenabled
- tccounter=1
- dtcounter=1-dtcounter
- If dtcounter=0
- Select dtformat
- Case 0
- title$=day$+"/"+month$+"/"+year$
- Case 1
- title$=month$+"/"+day$+"/"+year$
- Case 2
- title$=day$+"/"+month$
- Case 3
- title$=month$+"/"+day$
- End Select
- EndIf
- EndIf
- ;Dont adjust the clock title!
- SetWindowTitles_ Peek.l(Addr Window(0)),title$,-1
- Return
-
- ._default:
- waitstatus.w=-1
- popup$="NO"
- popkey$="ctrl lshift c"
- poppub$="ctrl lshift p"
- xpos$=Str$(ScreenWidth-160)
- ypos$="11"
- timeformat$="HH:MM.SS"
- dtformat$="DD/MM/YY"
- dt$="NO"
- Gosub _usesettings
- Return
-
- ._usesettings:
- twelvehour=(clockformat$="12")
- dtenabled.l=(dt$="YES")
- popupstatus.w=(popup$="YES")
- xpos.w=Val(xpos$)
- ypos.w=Val(ypos$)
- timeformat.w=0
- For n=1 To 2
- If tformat$(n)=timeformat$ Then timeformat.w=n-1
- Next n
-
- dformat.w=0
- For n=1 To 2
- If dformat$(n)=dtformat$ Then dtformat.w=n-1
- Next n
- suc=SetHotKey(0,popkey$)
- suc=SetHotKey(1,poppub$)
- Return
-